<?
include 'utils.php';

if ( !$_COOKIE['tracked'] )
{
	$dif = time() - $_GET['ts'];
	if ( abs($dif) < 60*60 )
	{
		$dif = round($dif/60);

		$m = new Mongo;
		$m->vremya->difs->update(
			array('_id' => $dif),
			array('$inc' => array('total' => 1)),
			array('upsert' => true)
		);
	}

	setcookie('tracked', 1);
}

$m = new Mongo;
$difs = $m->vremya->difs->find()->sort(array('total' => -1));
foreach ( $difs as $row )
{
	$max = $max ? $max : $row['total'];
	$cloud[$row['_id']] = round($row['total'] * 24 / $max) + 12;
}

ksort($cloud);

$mine_dif = round((time() - $_GET['ts'])/60);

$html = '<ul class="tags">';
foreach ( $cloud as $dif => $weight )
	$html .= '<li style="font-size: ' . $weight . 'px;' . ( $mine_dif == $dif ? 'color: red;' : '' ) . '"><span>' . format_minutes($dif) . '</span> ';

$html .= '</ul>';

echo "document.write('{$html}');";